//
//  RootController.m
//  healthApp
//
//  Created by william mu on 12-8-28.
//  Copyright (c) 2012年 Tencent. All rights reserved.
//

#import "RootController.h"
static id s_instance = nil;

@interface RootController ()

@end

@implementation RootController

@synthesize navController = m_navController;
@synthesize bottomBarController;

+(RootController*) sharedInstance
{
    return s_instance;
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    
    s_instance = self;
    m_controller = [[NSMutableArray array] retain];
    
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.view.frame = [[UIScreen mainScreen] applicationFrame];
}

-(void) loadController:(UIViewController*) controller
{
    [m_controller addObject: controller];
    
    [self.view addSubview:controller.view];
}

-(void) unloadController:(UIViewController *)controller
{
    NSAssert(controller.view.superview == self.view,@"Can't unload controller");
    
    [controller.view removeFromSuperview];
    
    [m_controller removeObject:controller];
}

-(void) unloadLastController
{
    UIViewController* controller = [m_controller lastObject];
    [controller.view removeFromSuperview];
    
    [m_controller removeObject:controller];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
    
    s_instance = nil;
    [m_controller release],m_controller = nil;

}


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}


@end
